package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.query.DestinationQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.util.AJaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){
        PageInfo<Destination> pageInfo =  destinationService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        List<Destination> toasts = destinationService.getToasts(qo.getParentId());
        model.addAttribute("toasts",toasts);
        return "destination/list";
    }

    @RequestMapping("changeHotValue")
    @ResponseBody
    public AJaxResult changeHotValue(int hot, Long id){
        destinationService.changeHotValue(hot,id);
        return AJaxResult.SUCCESS();
    }

    @RequestMapping("/setInfo")
    @ResponseBody
    public AJaxResult setInfo(Long id,String info){
        destinationService.setInfo(id,info);
        return AJaxResult.SUCCESS();
    }

    @RequestMapping("delete")
    @ResponseBody
    public AJaxResult delete(Long id){
        destinationService.delete(id);
        return AJaxResult.SUCCESS();
    }
}
